package com.example.disconf.demo.task;

import java.text.MessageFormat;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baidu.disconf.client.usertools.DisconfDataGetter;

/**
 * 演示分布式配置文件、分布式配置的更新Demo
 *
 * @author liaoqiqi
 * @version 2014-6-17
 */
@Service
public class DisconfDemoTask {

    protected static final Logger LOGGER = LoggerFactory.getLogger(DisconfDemoTask.class);

    /**
     *
     */
    public int run() {

        try {
            while (true) {
                LOGGER.info(DisconfDataGetter.getByFile("redis.properties").toString());
//                if (DisconfDataGetter.getByFile("autoconfig.properties").containsKey("auto")) {
//                    LOGGER.info(DisconfDataGetter.getByFile("autoconfig.properties").get("auto").toString());
//                }
//                if (DisconfDataGetter.getByFileItem("autoconfig.properties", "auto") != null) {
//                    LOGGER.info(DisconfDataGetter.getByFileItem("autoconfig.properties", "auto").toString());
//                }
//                LOGGER.info(DisconfDataGetter.getByFile("autoconfig.properties").get("auto").toString());
                Thread.sleep(3000);
            }
        } catch (Exception e) {

            LOGGER.error(e.toString(), e);
        }

        return 0;
    }
}
